﻿using System;
using System.Collections.Generic;
using System.Text;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.List {

    /// <summary>
    /// isMember(element, lst);
    /// 
    /// Example:
    /// echo(isMember(2, [1,2,3]));
    /// the expected result is true
    /// </summary>
    public class MemberOfNode : FuncNode {

        public MemberOfNode()
            : base() {
            this.Value = "isMember";
        }

        public override object Evaluate() {
            if (Parameters.Count < 2) {
                throw new ArgumentException(
                    "usage: isMember(element, lst)");
            }

            object value = Parameters[1].Evaluate();
            List<object> lst 
                = Parameters[0].Evaluate() as List<object>;

            return lst.Contains(value);
        }
    }
}
